package com.wn.ziroom.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@EnableConfigurationProperties(AlipayProperties.class)
@Configuration
public class AlipayConfig {


    @Bean
    public AlipayClient alipayClient(AlipayProperties alipayProperties){
        return new DefaultAlipayClient(
                alipayProperties.getGatewayUrl(),
                alipayProperties.getApp_id(),
                alipayProperties.getMerchant_private_key(),
                "json",
                alipayProperties.getCharset(),
                alipayProperties.getAlipay_public_key(),
                alipayProperties.getSign_type());
    }

    @Bean("alipayRequest")
    @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) //-- 默认score是单例的！
    public AlipayTradePagePayRequest alipayTradePagePayRequest (AlipayProperties alipayProperties){
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(alipayProperties.getReturn_url());
        alipayRequest.setNotifyUrl(alipayProperties.getNotify_url());
        return alipayRequest;
    }

    @Bean("alipayProductionRequest")
    @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) //-- 默认score是单例的！
    public AlipayTradePagePayRequest alipayTradePagePayProductionRequest(AlipayProperties alipayProperties){
        AlipayTradePagePayRequest alipayProductionRequest = new AlipayTradePagePayRequest();
        alipayProductionRequest.setReturnUrl(alipayProperties.getProductionReturn_url());
        alipayProductionRequest.setNotifyUrl(alipayProperties.getNotify_url());
        return alipayProductionRequest;
    }




}
